<template>
    <div>
        <el-dialog :title="title" :visible.sync="dialogVisible" width="40%" @close="handleClose">
            <el-form :model="form" :inline="true" :rules="rules" ref="form" label-width="150px" class="demo-ruleForm">
                <el-form-item label="企业邀请码" prop="inviteCode">
                    <el-input v-model="form.inviteCode"></el-input>
                </el-form-item>
               
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="submitForm">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
// import { invitationCode } from "@/request/api/link"
import { invitationCode } from "@/request/api/user"
import rulesUtil from "@/utils/rules"//引入
export default {
    data() {
        return {
            dialogVisible: false,
            type: "",
            title: "",
            form: {
                inviteCode:''
            },
            imgUrl: '',
            rules: {
                inviteCode: [
                    { required: true, message: '请输入企业邀请码', trigger: 'blur' },
                ],
                // galleryful: [
                //     { required: true, validator: rulesUtil.FormValidate.Form().checkInterNumRequired, trigger: 'blur' },
                // ],
                // linkUrl: [
                //     { required: true, message: '请输入链接地址', trigger: 'blur' },
                // ]
            },
            imageUploadUrl: '/dev-api/file/upload/uploadNotQR',
            dataTree: [],
            selectCate: {
                checkStrictly: false,
                label: "name",
                children: "children",
                value: "id",
                getCheckedNodes: true,
                expandTrigger: "hover",
                emitPath: true
            },
        };
    },

    methods: {
        open(type, info) {
            this.type = type;
            this.dialogVisible = true;
           
                this.title = "企业邀请码";
                let params = {
                    inviteCode:'',
                }
                this.form = params
          
        },
      
        // 区划
        selectValue(val) {
            this.$refs.cascader2.dropDownVisible = false;
        },
        handleClose() {
            this.$emit('getTrain')
            this.$refs.form.resetFields();

        },
      
        // 创建
        submitForm() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    const loading = this.$loading({
                        lock: true,
                        text: 'Loading',
                        spinner: 'el-icon-loading',
                        background: 'rgba(0, 0, 0, 0.7)'
                    });
                   
                        let params = { 
                            inviteCode:this.form.inviteCode
                         }
                        invitationCode({},params).then((res) => {
                            loading.close();
                            if (res.data.code === 200) {
                                this.$message({
                                    message: res.data.message,
                                    type: "success",
                                });
                                this.dialogVisible = false
                                 

                            } else {
                                this.$message.error(res.data.message);
                            }
                        });
                    
                } else {
                    return false;
                }
            });
        },
    },
};
</script>
<style lang="less" scoped>
.el-input {
    width: 380px;
}

.el-cascader {
    width: 380px;
}

.el-textarea {
    width: 380px;
}

.el-radio-group {
    width: 380px;
}

.el-date-editor {
    width: 380px;
}

/deep/.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 120px;
    height: 120px;
    line-height: 120px;
    text-align: center;
}

.avatar {
    width: 120px;
    height: 120px;
    display: block;
}
</style>

